package wnxy.wn44.shopwn.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.HandlerInterceptor;
import wnxy.wn44.shopwn.utils.CookieUtils;


import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Slf4j
@Order(1)
public class FirstIntercepter implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Cookie cookie = CookieUtils.getCookie("userId", request.getCookies());
        if (cookie == null){
            //-- 没有这个键值对，等价于没有的登录，该去登录页面
            response.sendRedirect("login.html");
        }
        return true;
    }
}
